﻿using System;
using System.Collections;
using UnityEngine;

namespace GameFramework.common
{
    public class DieScript:MonoBehaviour
    {
        public float liveTime = 3f;
        private Coroutine dieCorotine;
        private void Start()
        {
            dieCorotine = StartCoroutine(checkDie());
        }

        private IEnumerator checkDie()
        {
            if (liveTime <= 0)
            {
                Debug.Log("生存时间不大于0，立即销毁！");
                Destroy(gameObject);
                yield return null;
            }
            else
            {
                yield return new WaitForSeconds(liveTime);
                Destroy(gameObject);
            }
            
        }

        private void OnDestroy()
        {
            if (dieCorotine != null)
            {
                StopCoroutine(dieCorotine);
            }
        }
    }
}